<?php

  require_once "JooS/Server/Resource/DataContent.php";

  class JooS_Server_Resource_DataElement extends JooS_Server_Resource_DataContent implements IteratorAggregate {
    private $_childNodes = null;

    public function __construct($name) {
      parent::__construct($name);

      require_once "JooS/Server/Resource/DataElement/List.php";
      $this->_childNodes = new JooS_Server_Resource_DataElement_List();
    }

    public function __set($name, $value) {
      switch ($name) {
        case "nodeName":
        case "nodeValue":
        case "childNodes":
        case "attributes":
          break;
        default:
          $this->_childNodes[$name] = $value;
          break;
      }
    }

    public function __get($name) {
      switch ($name) {
        case "nodeName":
        case "attributes":
          return parent::__get($name);
        case "nodeType":
          return self::DATA_ELEMENT_NODE;
        case "value":
          $value = array();
          foreach ($this->_childNodes as $k => $v) {
            $value[$k] = $v->value;
          }
          return $value;
        case "nodeValue":
          $nodeValue = parent::__get($name);
          foreach ($this as $k => $v)
            $nodeValue[] = $this->_childNodes[$k]->nodeValue;

          return $nodeValue;
        case "childNodes":
          return $this->_childNodes;
        default:
          return $this->_childNodes[$name];
      }
    }

    public function __isset($name) {
      switch ($name) {
        case "nodeName":
        case "nodeValue":
        case "childNodes":
        case "attributes":
          return true;
          break;
        default:
          return isset($this->_childNodes[$name]);
          break;
      }
    }

    public function __unset($name) {
      switch ($name) {
        case "nodeName":
        case "nodeValue":
        case "childNodes":
        case "attributes":
          break;
        default:
          unset($this->_childNodes[$name]);
          break;
      }
    }

    public function getIterator() {
      return new ArrayIterator($this->_childNodes);
    }
  }

?>